/* eslint-disable no-dupe-class-members */
'use strict';

const BaseService = require('./base');

class ThemeLike extends BaseService {

  async add(theme_id, user_id) {
    return await this.ctx.model.ThemeLike.create({
      theme_id, user_id
    });
  }

  async delete(theme_id, user_id) {
    return await this.ctx.model.ThemeLike.destroy({
      where: {
        theme_id,
        user_id
      }
    });
  }
  
  async findByThemeIdUserId(theme_id, user_id) {
    return await this.ctx.model.ThemeLike.findOne({
      where: {
        theme_id,
        user_id
      }
    });
  }

  async getUserId(themeId) {
    const like = await this.ctx.model.ThemeLike.findAll({
      where: {
        theme_id: themeId
      }
    })
    const userId = [];
    if (like) {
      like.forEach(l => {
        userId.push(l.user_id);
      })
    }
    return userId;
  }
}

module.exports = ThemeLike;
